package xyz.xiaomeiqiu.study;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.xiaomeiqiu.study.domain.Klass;
import xyz.xiaomeiqiu.study.domain.School;
import xyz.xiaomeiqiu.study.domain.Student;

import javax.annotation.Resource;
import java.util.Map;

@SpringBootApplication
@RestController
public class App {

    @Resource
    private School school;

    @Resource
    private ApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

    @GetMapping("/school")
    public School aa() {
        lookupCollectionByType(applicationContext);
        school.ding();
        return school;
    }

    private static void lookupCollectionByType(BeanFactory beanFactory) {
        if(beanFactory instanceof ListableBeanFactory){
            ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory;
            Map<String, School> beansOfType = listableBeanFactory.getBeansOfType(School.class);
            System.out.println("查找到的所有school bean:"+beansOfType);
        }
    }
}
